<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../js/vue.js"></script>
  </head>
  <body>
    <div id="box">
      <qq></qq>
    </div>
    <!-- fu -->
    <template id="box1">
      <div>
        <h1>我是父组件:{{textNew}}</h1>
     
        <nan @send="acceptMag"></nan>
      </div>
    </template>

    <!-- zi -->
    <template id="box2">
      <div>
        <h1>我是子组件: {{mag}}</h1>
        <button @click="sub">传递</button>
      </div>
    </template>

    <script>
      //zi
      const two = {
        template: "#box2",
        data() {
          return {
            mag:"我是子组件"
          }
        },
        //事件传递
        methods: {
          sub(){
            console.log(123);
            //自定义事件    this.$emit("事件名称"，传递的数据)
            this.$emit("send",this.mag)
          }
        },
      };

      //fu
      const ane = {
        template: "#box1",
       
        //在这给子组件声明
        components: {
          nan: two,
         
        },
        data() {
          return {
            textNew:''
          }
        },
        methods:{
          acceptMag(v){
            this.textNew=v
            console.log( this.textNew);
          }
      },

      };

      new Vue({
        el: "#box",
        components: {
          qq: ane,
        },
      });
    </script>
  </body>
</html>
